<?php
/**
 * swoole所有的task任务，在这里分发
 *
 */
namespace app\common\lib\task;
use app\common\lib\ali\Sms;
use app\common\lib\redis\Predis;
use app\common\lib\Redis;
use app\common\lib\Util;
class Task{
    /**
     * 异步发送
     * @param $data
     * @return mixed
     */
    public function sendSms($data,$serv){

        try{
            $res= Sms::sendSms($data['phone'],$data['code']);
        }catch (\Exception $e){
            return Util::show(-1,"阿里大于内部异常");
        }
        if($res->Code ==="OK"){
            Predis::getInstance()->set(Redis::smsKey($data['phone']),$data['code']);
        }else{
            return false;
        }
        return true;
    }

    /**
     * @param $data
     */
    public function pushLive($data,$serv)
    {
        $clients = Predis::getInstance()->sMembers('live_game_key');

        foreach ($clients as $fd){
           $a= $serv->connection_info($fd);
            if($a && isset($a["websocket_status"]) && intval($a["websocket_status"])>0){
                $serv->push($fd,json_encode($data));
            }
        }
    }
}